package com.doform.android.xianggucheng.activity;

import android.widget.ImageView;
import android.widget.ProgressBar;

import com.bumptech.glide.Glide;
import com.doform.android.xianggucheng.R;
import com.doform.android.xianggucheng.bean.request_bean.ReqErCode;
import com.doform.android.xianggucheng.retrofit.ApiSpecTransformer.DialogTransformer;
import com.doform.android.xianggucheng.retrofit.HttpManager;
import com.doform.android.xianggucheng.retrofit.subscriber.ErrorHandleSubscriber;

import butterknife.BindView;
import io.reactivex.annotations.NonNull;

/**
 * 作者 Y_MS
 * Created by ${APEN} on 2017-08-12.
 * GitHub：https://github.com/cxydxpx
 */

public class ErCodeActivity extends BaseTitleActivity {

    @BindView(R.id.imageview)
    ImageView imageView;

    @BindView(R.id.progressBar)
    ProgressBar mProgressBar;

    @Override
    protected int layoutResId() {
        return R.layout.activity_er_code;
    }

    @Override
    protected void initData() {
        super.initData();
        getDataForService();
    }

    private void getDataForService() {
        HttpManager
                .instance()
                .getErCode(new ReqErCode())
                .compose(new DialogTransformer<String>(mProgressBar))
                .subscribe(new ErrorHandleSubscriber<String>() {
                               @Override
                               public void onNext(@NonNull String s) {
                                   Glide
                                           .with(ErCodeActivity.this)
                                           .load(s)
                                           .error(R.mipmap.logo) // 异常图片显示
                                           .into(imageView);
                               }
                           }
                );
    }

    @Override
    protected void showView() {
        titleBar.setTextTitle("二维码名片");
    }
}
